package com.vsu.bookstore.mvc.ui.window;

import com.vaadin.data.util.BeanItem;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.vsu.bookstore.mvc.model.bean.BookStoreItem;
import com.vsu.bookstore.mvc.ui.widgets.ItemForm;

@SuppressWarnings("serial")
public class ItemWindow extends Window
{

  private final ItemForm form = new ItemForm();

  public ItemWindow()
  {
    super();
    setCaption("Item Details");
    final VerticalLayout layout = new VerticalLayout();
    setContent(layout);
    layout.setSizeUndefined();
    setClosable(false);
    setResizable(false);
    setModal(true);
    setDraggable(false);
    getContent().addComponent(form);
    center();
  }


  public void resetItemDS(final BookStoreItem bean)
  {
    final BeanItem<BookStoreItem> bt = new BeanItem<BookStoreItem>(bean);
    form.setItemDataSource(bt);
  }

  public void setContentsLocked(final boolean readOnly)
  {
    form.setReadOnly(readOnly);
  }
}